<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('产权信息变更记录') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('公司名称')" prop="companyId">
        <el-input
          v-model="queryParams.companyId"
          :placeholder="$t('公司名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="propertyCompanyList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('公司名称')" align="center" prop="companyId" width="250">
        <template slot-scope="scope">
          {{ scope.row.companyId }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('登记类型(一级)')" align="center" prop="registrationType" :formatter="registrationTypeFormat" />
      <el-table-column :label="$t('登记类型(二级)')" align="center" prop="twoType" />
      <el-table-column :label="$t('登记类型(三级)')" align="center" prop="threeType" />
      <el-table-column :label="$t('事件发生日')" align="center" prop="behaviorTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.behaviorTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('说明备注')" align="center" prop="editText" width="500px" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" fixed="right" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['property:propertyCompany:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('变更记录') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产权信息对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <propertyCompanyForm ref="propertyCompanyForm" />
    </el-dialog>
  </div>
</template>

<script>
  import { listPropertyCompany, exportPropertyCompany } from '@/api/company/propertyCompany/propertyCompany'
  import propertyCompanyForm from './propertyCompanyForm.vue'
  export default {
    components: {
      propertyCompanyForm
    },
    data() {
      return {
        currencyOption: [],
        organizationalOption: [],
        mainIndustriesOption: [],
        institutionsOption: [],
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 产权信息表格数据
        propertyCompanyList: [],
        // 弹出层标题
        title: '产权信息',
        // 是否显示弹出层
        formOpen: false,
        // 登记类型(一级)字典
        registrationTypeOptions: [],

        // 经济行批准机构字典
        jcApprovalAgencyOptions: [],

        // 公告方式字典
        jcPublicAnnouncementOptions: [],

        // 转让价款支付方式字典
        jcPricePaymentMethodOptions: [],

        // 新增出资人类型字典
        zzNewInvestorsTypeOptions: [],

        // 查询参数
        queryParams: {
          changeId: this.$route.query.id,
          companyId: undefined,
          creditCode: undefined,
          organizationalForm: undefined,
          mainIndustries: undefined,
          institutionsCategory: undefined,
          last: 'N',
          pageNum: 1,
          pageSize: 10
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      }
    },
    created() {
      this.getList()

      this.getDicts('currency').then(response => {
        this.currencyOption = response.data
      })
      this.getDicts('property_organizational').then(response => {
        this.organizationalOption = response.data
      })
      this.getDicts('deal_industry_focus').then(response => {
        this.mainIndustriesOption = response.data
      })
      this.getDicts('property_Institutions').then(response => {
        this.institutionsOption = response.data
      })
      this.getDicts('registration_type').then(response => {
        this.registrationTypeOptions = response.data
      })
      this.getDicts('jc_approval_agency').then(response => {
        this.jcApprovalAgencyOptions = response.data
      })
      this.getDicts('jc_public_announcement').then(response => {
        this.jcPublicAnnouncementOptions = response.data
      })
      this.getDicts('jc_price_payment_method').then(response => {
        this.jcPricePaymentMethodOptions = response.data
      })
      this.getDicts('new_investors_type').then(response => {
        this.zzNewInvestorsTypeOptions = response.data
      })
    },
    methods: {
      /** 查询产权信息列表 */
      getList() {
        this.loading = true
        listPropertyCompany(this.queryParams).then(response => {
          this.propertyCompanyList = response.rows
          this.total = response.total
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      },

      currencyFormat(row) {
        return this.selectDictLabel(this.currencyOption, row.currency)
      },
      organizationalFormFormat(row) {
        return this.selectDictLabel(this.organizationalOption, row.organizationalForm)
      },
      mainIndustriesFormat(row) {
        return this.selectDictLabel(this.mainIndustriesOption, row.mainIndustries)
      },
      institutionsFormat(row) {
        return this.selectDictLabel(this.institutionsOption, row.institutionsCategory)
      },
      // 登记类型(一级)字典翻译
      registrationTypeFormat(row, column) {
        console.log(column)
        return this.selectDictLabel(this.registrationTypeOptions, row.registrationType)
      },
      // 经济行批准机构字典翻译
      jcApprovalAgencyFormat(row, column) {
        console.log(column)
        return this.selectDictLabel(this.jcApprovalAgencyOptions, row.jcApprovalAgency)
      },
      // 公告方式字典翻译
      jcPublicAnnouncementFormat(row, column) {
        console.log(column)
        return this.selectDictLabel(this.jcPublicAnnouncementOptions, row.jcPublicAnnouncement)
      },
      // 转让价款支付方式字典翻译
      jcPricePaymentMethodFormat(row, column) {
        console.log(column)
        return this.selectDictLabel(this.jcPricePaymentMethodOptions, row.jcPricePaymentMethod)
      },
      // 新增出资人类型字典翻译
      zzNewInvestorsTypeFormat(row, column) {
        console.log(column)
        return this.selectDictLabel(this.zzNewInvestorsTypeOptions, row.zzNewInvestorsType)
      },

      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          dealId: undefined,
          registrationType: undefined,
          registrationTypeTwo: undefined,
          registrationTypeThree: undefined,
          companyId: undefined,
          creditCode: undefined,
          registeredCapital: undefined,
          currency: undefined,
          organizationalForm: undefined,
          mainIndustries: undefined,
          institutionsCategory: undefined,
          detailsRegistered: undefined,
          legalPerson: undefined,
          estiblishDate: undefined,
          isMergeTable: undefined,
          businessScope: undefined,
          propertyRemark: undefined,
          jcPropertyTrading: undefined,
          jcPropertyTime: undefined,
          jcWithdrawalWay: undefined,
          jcReasonTransfer: undefined,
          jcProportionTransferred: undefined,
          jcTransfereeName: undefined,
          jcTransfereeIndustryType: undefined,
          jcRegistrationPlace: undefined,
          jcIsNationalHoldings: undefined,
          jcAssetValue: undefined,
          jcAssessedValue: undefined,
          jcApprovalAgency: undefined,
          jcForDays: undefined,
          jcPublicAnnouncement: undefined,
          jcTradingVolume: undefined,
          jcEvaluationValue: undefined,
          jcPricePaymentMethod: undefined,
          jcPaymentRemark: undefined,
          xyProportionTransferred: undefined,
          xyTransfereeName: undefined,
          xyRegistrationPlace: undefined,
          xyIsNationalHoldings: undefined,
          xyTransferPrice: undefined,
          wcProportionTransferred: undefined,
          wcTransfereeName: undefined,
          zzNewInvestors: undefined,
          zzNewInvestorsType: undefined,
          zzProportionalCapitalIncrease: undefined,
          zzCompanyValuation: undefined,
          zzAuditedNetAssets: undefined,
          jzCapitalReductions: undefined,
          jzCompanyValuation: undefined,
          jzAuditedNetAssets: undefined,
          twoType: undefined,
          threeType: undefined,
          delFlag: undefined,
          createBy: undefined,
          createTime: undefined,
          updateBy: undefined,
          updateTime: undefined
        }
        this.resetForm('form')
      },
      /** 搜索按钮操作 */
      queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
      },
      /** 新增按钮操作 */
      addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
          this.$refs.propertyCompanyForm.init(null)
        })
      },
      /** 修改按钮操作 */
      updateHandle(row, edit) {
        this.formOpen = true
        this.$nextTick(() => {
          // 调用form页面的 init 方法初始化数据
          this.$refs.propertyCompanyForm.init(row, edit)
        })
      },
      /** 删除按钮操作 */
      deleteHandle(row, edit) {
        this.formOpen = true
        this.$nextTick(() => {
          // 调用form页面的 init 方法初始化数据
          this.$refs.propertyCompanyForm.init(row, edit)
        })
        // this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        //     confirmButtonText: this.$t('确定'),
        //     cancelButtonText: this.$t('取消'),
        //     type: 'warning'
        // }).then(() => {
        //     return delPropertyCompany(row.id)
        // }).then(() => {
        //     this.getList()
        //     this.msgSuccess(this.$t('删除成功'))
        // }).catch(() => {
        //     this.loading = false
        // })
      },
      stop(data) {
        data.actId = data.id
        this.stopProcess(data)
      },
      /** 导出按钮操作 */
      exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(() => {
          return exportPropertyCompany(queryParams)
        }).then(response => {
          this.download(response.msg)
        }).catch(() => {
        })
      },
      // 终止流程按钮是否展示
      stopBtn: function() {
        if (this.busData.actStatus === 'D') {
          return true
        } else {
          return false
        }
      }
    }
  }
</script>
